#include "game.h"

s_back *g_back = NULL;

int background_end()
{
  SDL_FreeSurface(g_back->img1);
  SDL_FreeSurface(g_back->img2);
  free(g_back);
  return (0);
}

int background_update(SDL_Surface *area)
{
  g_back->y += 2;
  if (g_back->y >= g_back->img1->h)
    g_back->y = 0;
  draw_rect(g_back->x, g_back->y, g_back->img1, area);
  draw_rect(g_back->x, g_back->y - g_back->img2->h, g_back->img2, area);
  return (0);
}

int background_init(int width,int height)
{
  char *picture_name;

  SDL_Surface *img1 = NULL;
  SDL_Surface *img2 = NULL;

  picture_name = "src/picture/back_pink.jpeg";
  img1 = IMG_Load(picture_name);
  img2 = IMG_Load(picture_name);
  g_back = malloc(sizeof(s_back));
  g_back->width = width;
  g_back->height = height;
  g_back->x = 0;
  g_back->y = 0;
  g_back->img1 = img1;
  g_back->img2 = img2;

  return (0);
}
